package com.jzo2o.foundations.controller.operation;

import com.jzo2o.common.model.PageResult;
import com.jzo2o.foundations.mapper.ServeMapper;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.IServeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 区域服务管理 前端控制器
 * </p>
 *
 * @author xumin
 * @since 2024-09-06
 */

@Validated
@RestController("operationServeController")
@RequestMapping("/operation/serve")
@Api(tags = "运营端 - 区域服务管理相关接口")
public class ServeController {

    //import javax.annotation.Resource;
    @Resource
    private IServeService iServeService;

    //import org.springframework.beans.factory.annotation.Autowired;
    @Autowired
    private ServeMapper serveMapper;

    @GetMapping("/page")
    @ApiOperation("区域服务分页查询")
    public PageResult<ServeResDTO> page(ServePageQueryReqDTO servePageQueryReqDTO){
        return iServeService.page(servePageQueryReqDTO);
    }

    @PostMapping("/batch")
    @ApiOperation("区域服务新增")
    public void add(@RequestBody List<ServeUpsertReqDTO> serveUpsertReqDTOList){
        iServeService.batchInsert(serveUpsertReqDTOList);
    }


    @PutMapping("/{id}")
    @ApiOperation("区域服务管理价格修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
            @ApiImplicitParam(name = "price", value = "价格", required = true, dataTypeClass = BigDecimal.class)
    })
    public void update(@NotNull(message = "id不能为空") @PathVariable("id") Long id,
                       @NotNull(message = "price不能为空") @RequestParam("price") BigDecimal price) {
        iServeService.update(id, price);
    }


    @PutMapping("/onSale/{id}")
    @ApiOperation("区域服务管理上架")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class)
    })
    public void onSale(@NotNull(message = "id不能为空") @PathVariable("id") Long id) {
        iServeService.onSale(id);
    }
}
